<?php
ob_start();
session_start();
include "checksession.php";
include_once "../connect.php";

$alt_Id = $_GET["alt_Id"];

if (!empty($alt_Id)) {

    $sql = "SELECT * ,altcomservice.* FROM `altcomservice` LEFT JOIN depart ON altcomservice.de_id = depart.id                                                                                
                                         LEFT JOIN employee ON altcomservice.emp_id = employee.emp_id                                       
                                         LEFT JOIN comname ON altcomservice.cn_id = comname.cn_id
                                         lEFT JOIN mtncomservice ON altcomservice.alt_Id = mtncomservice.alt_Id
                                         LEFT JOIN rstcomservice ON altcomservice.alt_ID = rstcomservice.alt_ID
                                          LEFT  JOIN product_detail ON comname.cn_number =  product_detail.pd_id
                                         WHERE altcomservice.alt_Id = '$alt_Id' 
                                            ";

    $rs = mysql_query($sql);

    if ($rs) {

        //alt main
        $r = mysql_fetch_array($rs);
       
        
        $altDate = $r['alt_Date'];
        $altTime = $r['alt_Time'];
        $txtDatetAlt = date('d-m-Y', strtotime($altDate));
        $txtTimeAlt = date('H:i', strtotime($altTime));

        //Date Maintennace
        $matDate = $r['mtn_date'];
        if ($matDate != NULL) {
            $txtDateMtn = date('d-m-Y', strtotime($matDate));
        } else {
            $txtDateMtn = NULL;
        }
        $matTime = $r['mtn_time'];
        if ($matTime != NULL) {
            $txtTimeMtn = date('H:i', strtotime($matTime));
        } else {
            $txtTimeMtn = NULL;
        }

        //Date Result IT
        $rstDateIt = $r['rst_sentDate'];
        if ($rstDateIt != NULL) {
            $txtDateRstIT = date('d-m-Y', strtotime($rstDateIt));
        } else {
            $txtDateRstIT = NULL;
        }
        $rstTimeIt = $r['rst_sentTime'];
        if ($rstTimeIt != NULL) {
            $txtTimeRstIt = date('H:i', strtotime($rstTimeIt));
        } else {
            $txtTimeRstIt = NULL;
        }

        //Date Result EMP
        $rstDate = $r['rst_inDate'];
        if ($rstDate != NULL) {
            $txtDateRst = date('d-m-Y', strtotime($rstDate));
        } else {
            $txtDateRst = NULL;
        }
        $rstTime = $r['rst_inTime'];
        if ($rstTime != NULL) {
            $txtTimeRst = date('H:i', strtotime($rstTime));
        } else {
            $txtTimeRst = NULL;
        }
        
        $altDateAlt = $r['alt_Date'];
        $altTimeAlt = $r['alt_Time'];
        $txtDatetAltDate = date('d-m-Y', strtotime($altDateAlt));
        $txtTimeAltTime = date('H:i', strtotime($altTimeAlt));
        
        
        
    } else {
        echo mysql_error();
    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
        <link rel="stylesheet" href="../css/style.css"/>
        <!--<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />-->
        <!--<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css">  them orang -->
        <link type="text/css" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
        <script src="../js/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/jquery/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript" src="../js/jquery/timepicker.js"></script>
      <!--<script src="../js/jquery/ui/jquery-ui.js"></script>-->
        <script type="text/javascript">
            $(function() {
                $('#datetime').datepicker({
                    duration: '',
                    showTime: true,
                    constrainInput: false
                });
            });

            $(function() {
                $('#datetimeRstIt').datepicker({
                    duration: '',
                    showTime: true,
                    constrainInput: false
                });
            });

            $(function() {
                $('#datetimeRst').datepicker({
                    duration: '',
                    showTime: true,
                    constrainInput: false
                });
            });

            $(document).ready(function() {

                $(".slidingDivAlt").hide();
                $(".show_hideAlt").show();

                $('.show_hideAlt').click(function() {
                    $(".slidingDivAlt").slideToggle();
                });

            });

            $(document).ready(function() {

                $(".slidingDivMtn").hide();
                $(".show_hideMtn").show();

                $('.show_hideMtn').click(function() {
                    $(".slidingDivMtn").slideToggle();
                });

            });

            $(document).ready(function() {

                $(".slidingDivRes").hide();
                $(".show_hideRes").show();

                $('.show_hideRes').click(function() {
                    $(".slidingDivRes").slideToggle();
                });

            });
        </script>
        <script language="javascript">
            function CheckValidate()
            {
                if (eval("document.frmMainMtn.txtError.value") == "") {
                    alert("กรุณากรอกช่อง รายละเอียดการซ่อม");
                    eval("document.frmMainMtn.txtError.focus();")
                    return false;
                }

                if (eval("document.frmMainMtn.datetime.value") == "") {
                    alert("กรุณากรอกช่อง วันเวลาที่รับ");
                    eval("document.frmMainMtn.datetime.focus();")
                    return false;
                }
            }

            function CheckValidateRst()
            {
                if (eval("document.frmMainRst.txtResult.value") == "") {
                    alert("กรุณากรอกช่อง รายละเอียดการซ่อม");
                    eval("document.frmMainRst.txtResult.focus();")
                    return false;
                }

                if (eval("document.frmMainRst.datetimeRstIt.value") == "") {
                    alert("กรุณากรอกช่อง วันเวลาที่ส่ง");
                    eval("document.frmMainRst.datetimeRstIt.focus();")
                    return false;
                }

                if (eval("document.frmMainRst.datetimeRst.value") == "") {
                    alert("กรุณากรอกช่อง วันเวลาที่รับ");
                    eval("document.frmMainRst.datetimeRst.focus();")
                    return false;
                }


                if (eval("document.frmMainRst.txtMtn.value") == "") {
                    alert("ยังไม่ได้ดำเนินการซ่อม");
                    eval("document.frmMainRst.txtMtn.focus();")
                    return false;
                }




            }

        </script>
    </head>
    <body>
        <div align="center" >
            <a href="#" class="show_hideAlt"><span class="nameTitle">แจ้งซ่อมคอมพิวเตอร์ </span></a>
            <div class="slidingDivAlt">
                <form  
                    method="Post"
                    action="altServiceComUpSave.php"
                    name ="frmMain" id="frmMain"
                    />             
                <table class="inputcontenttable">

                    <tr valign="top">
                        <td>รหัสพนักงาน</td>
                        <td><input  id="txtEmpid" name="txtEmpid" type="text" value="<?= $r['emp_id'] ?>" readonly/></td> 
                        <td width="50px"></td>
                        <td>ผู้แจ้ง</td>
                        <td><input id="txtNameEng" name="txtNameEng" type="text" value="<?= $r['emp_nameTh'] ?>"readonly/></td>      
                    </tr>
                    <tr valign="top" >
                        <td>แผนกฝ่าย</td>
                        <td><input id="txtDepartment"  name="txtDepartment" type="text" value="<?= $r['departname'] ?>" readonly/></td>  
                        <td width="50px"></td>
                        <td>รหัสเครื่อง</td>
                        <td><input id="txtNumber"  name="txtNumber" type="text" value="<?= $r['pd_name'] ?>" readonly /></td>
                    </tr>
                    <tr valign="top" >
                        <td>STATUS</td>
                        <td colspan="4"> 
                            <select name="opStatus" id="opStatus">			
                                <?
                                $strSQL = "SELECT * FROM altcomservice WHERE alt_Id = '$alt_Id'";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["alt_status"]; ?>"><?= $objResuut["alt_status"]; ?></option>		
                                    <option value="Wait">Wait</option>
                                    <option value="Action">Action</option>
                                    <option value="Finish">Finish</option>
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top" >
                    </tr>
                    <tr valign="top" >
                        <td>อาการเสีย</td>
                        <td colspan="4"><textarea id="txtError"  rows="4" cols="50" name="txtError" style="width: 445px"/><? echo $r['alt_Error']; ?></textarea></td> 
                    </tr>

                    <tr valign="top">
                        <td colspan="5">                      
                            <input name="chkProgram" type="checkbox" value="Program" id="chkProgram"  <?php
                                if ($r[alt_Program] == 'Program') {
                                    echo "CHECKED";
                                }
                                ?>/>โปรแกรม
                        </td>                                                                                                                                             
                    </tr>
                    <tr valign="top">    
                        <td colspan="5">
                            <input name="chkDevice" type="checkbox"  value="Device" id="chkDevice" <?php
                            if ($r[alt_Device] == 'Device') {
                                echo "CHECKED";
                            }
                                ?>/>  อุปกรณ์ต่อพ่วงและคอมพิวเตอร์                                                                                                                                                                                                                                                   
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            วันที่แจ้ง <input type="text" name="txtDate" value="<?= $txtDatetAlt ?>" readonly>
                        </td>
                        <td colspan="3">
                            เวลาที่แจ้ง <input type="text" name="txtTime" value="<?= $txtTimeAlt ?>" readonly>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" align="center"><input type="submit" name="Submit" value="Save" style="height: 30px; width: 120px"  /></td>
                    </tr>     
                    <input type="hidden" name="alt_Id" value="<?= $r['alt_Id'] ?>"/>
                    <input type="hidden" name="de_id" value="<?= $r['de_id'] ?>"/>
                    <input type="hidden" name="cn_id" value="<?= $r['cn_id'] ?>"/>
                    <input type="hidden" name="id_member" value="<?= $r['id_member'] ?>"/>             
                    </form>
                </table>
                <br/>
            </div>


            <a href="#" class="show_hideMtn"> <span class="nameTitle"> ดำเนินการซ่อม </span></a>
            <div class="slidingDivMtn">
                <form  
                    method="Post"
                    action="altSeviceComMaintenSave.php"
                    name ="frmMainMtn" id="frmMainMtn" OnSubmit="return CheckValidate();" />
                <table class="inputcontenttable">               
                    <tr valign="top">
                        <td><input id="chkCanSV" type="checkbox" name="chkCanSV" value="CanService" <?php
                            if ($r['mtn_can'] == 'CanService') {
                                echo "CHECKED";
                            }
                                ?> >สามารถซ่อมได้</td>
                    </tr>
                    <tr valign="top">                  
                        <td><input id="chkChgDev" type="checkbox" name="chkChgDev" value="ChangDevice" <?php
                            if ($r['mtn_chgDevice'] == 'ChangDevice') {
                                echo "CHECKED";
                            }
                                ?>>มีการเปลี่ยนอุปกรณ์</td>
                    </tr>
                    <tr valign="top">                  
                        <td><input id="chkNotChgDev" type="checkbox" name="chkNotChgDev" value="NotDevice" <?php
                            if ($r['mtn_notDevice'] == 'NotDevice') {
                                echo "CHECKED";
                            }
                                ?>>ไม่มีการเปลี่ยนอุปกรณ์</td>
                    </tr>
                    <tr valign="top">                  
                        <td><input id="chkNewProgram" type="checkbox" name="chkNewProgram" value="NewProgram" <?php
                            if ($r['mtn_newProgram'] == 'NewProgram') {
                                echo "CHECKED";
                            }
                                ?>>มีการลงโปรแกรมใหม่</td>
                    </tr>
                    <tr valign="top">                  
                        <td><input id="chkEditProgram" type="checkbox" name="chkEditProgram" value="EditProgram" <?php
                            if ($r['mtn_editProgram'] == 'EditProgram') {
                                echo "CHECKED";
                            }
                                ?>>มีการแก้ไขโปรแกรมใหม่</td>
                    </tr>
                    <tr valign="top" >
                        <td>รายละเอียอดการซ่อม</td>
                    </tr>
                    <tr>
                        <td colspan="2"><textarea id="txtError" rows="4" cols="50" name="txtmainten" style="width: 445px"><?= $r['mtn_detail'] ?></textarea></td> 
                    </tr>
                    <tr>
                        <td>วันเวลาที่รับ<input type="text" name="datetime" id="datetime" value="<?= $txtDateMtn, " ", $txtTimeMtn ?>"></td>
                    </tr>
                   
                    <tr>
                        <td align="center"><input type="submit" name="Submit" value="Save" style="height: 30px; width: 120px"/></td>
                    </tr>     
                    <input type="hidden" name="alt_Id" value="<?= $r['alt_Id'] ?>"/>
                    <input type="hidden" name="id_member" value="<?= $r['id_member'] ?>"/>
                    <input type="hidden" name="emp_id" value="<?= $r['emp_id'] ?>"/>
                    <input type="hidden" name="mtn_id" value="<?= $r['mtn_id'] ?>"/>
                    <input type="hidden" name="txtDatetAltDate" value="<?= $txtDatetAltDate ?>"/>
                    <input type="hidden" name="$txtTimeAltTime" value="<?= $txtTimeAltTime ?>" />
                    <input  type="hidden" name="opStatus" value="Action"/> 
                        
                    </form>
                </table>
            </div>



            <a href="#" class="show_hideRes"> <span class="nameTitle"> ผลการซ่อมและส่งมอบ </span></a>
            <div class="slidingDivRes">
                <form  
                    method="Post"
                    action="altServiceComResultSave.php"
                    name ="frmMainRst" id="frmMainRst" OnSubmit="return CheckValidateRst();" />
                <table class="inputcontenttable"> 
                    <tr valign="top">
                        <td>
                            <input type="radio" name="radResult" value="CanService" <?php
                            if ($r[rst_notCan] == 'CanService') {
                                echo "CHECKED";
                            }
                                ?>>สามารถใช้งานได้ตามปกติ<br>

                                    <input type="radio" name="radResult" value="NotCan" <?php
                                    if ($r[rst_notCan] == 'NotCan') {
                                        echo "CHECKED";
                                    }
                                    ?>>ไม่สามารถใช้งานได้ตามปกติ
                                        </td>
                                        </tr>
                                        <tr valign="top" >
                                            <td>รายละเอียอดการซ่อม</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><textarea id="txtResult" rows="4" cols="50" name="txtResult" style="width: 445px"><?= $r['rst_detail'] ?></textarea></td> 
                                        </tr>
                                        <tr>
                                            <td>
                                                เจ้าหน้าที่ฝ่ายเทคโนโลยีสารสนเทศ
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>วันเวลาที่ส่ง<input type="text" name="datetimeRstIt" id="datetimeRstIt" value="<?= $txtDateRstIT, " ", $txtTimeRstIt ?>"></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                เจ้าหน้าที่ผู้แจ้ง
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>วันเวลาที่รับ<input type="text" name="datetimeRst" id="datetimeRst" value="<?= $txtDateRst, " ", $txtTimeRst ?>"></td>
                                        </tr>        
                                        <tr>
                                            <td align="center"><input type="submit" name="Submit" value="Save" style="height: 30px; width: 120px" /></td>
                                        </tr>     
                                        <input type="hidden" name="alt_Id" value="<?= $r['alt_Id'] ?>"/>
                                        <input type="hidden" name="id_member" value="<?= $r['id_member'] ?>"/>
                                        <input type="hidden" name="emp_id" value="<?= $r['emp_id'] ?>"/>
                                        <input id="txtMtn" type="hidden" name="$mtn_id" value="<?= $r['mtn_id'] ?>"/>
                                        <input id="txtstatus" type="hidden" name="$alt_status" value="<?= $r['alt_status'] ?>"/>
                                        <input type="hidden" name="rst_id" value="<?= $r['rst_id'] ?>"/>	  
                                            <input  type="hidden" name="opStatus" value="Finish"/> 
                                        </form>
                                        </table>
                                        </div>
                                        </div>
                                        </body>
                                        </html>
